package org.lanqiao.tjut.control;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.ClassBean;
import org.lanqiao.tjut.bean.TeacherBean;
import org.lanqiao.tjut.myUtils.MyUtils;
import org.lanqiao.tjut.service.ServiceFactory;

public class SelectClassT extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		ClassBean classbean = (ClassBean) MyUtils.getNewInsdence(ClassBean.class);
		String secClassName = request.getParameter("classname");

		classbean.setClassname(secClassName);

		TeacherBean teaBean = (TeacherBean) request.getSession().getAttribute("LoginedUserT");

		classbean.setTeaname(teaBean.getTeaname());

		// 将教师新选课添加进课程表中
		int i = ServiceFactory.getSelectClassManagerServiceInstance().SavaClassT(classbean);
		if (i > 0) {
			MyUtils.logger_rootLogger.info("教师" + classbean.getTeaname() + "选择课程[" + classbean.getClassname() + "]成功！");
			// 添加完后，重新查询一次该老师所有的授课课程
			//List<ClassBean> lst = ServiceFactory.getSelectClassManagerServiceInstance().getAllClassInfo(classbean);
			// 将需要显示的结果(查询的所有用户信息)存入session缓存中
			//request.getSession().setAttribute("lst", lst);

			// 跳转到相应页面进行显示
			request.getRequestDispatcher("QueryAllClassInfo").forward(request, response);
		} else {
			request.getSession().setAttribute("pageErrorInfo", "课程信息加载失败！");
			response.sendRedirect("Logined/Error.jsp");
		}
	}

	

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}

	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}

}
